<?php
use common\modules\storage\widget\upload\Upload;
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use kartik\widgets\DateTimePicker;

/* @var $this yii\web\View */
/* @var $model common\modules\content\models\Article */
/* @var $categories common\modules\content\models\ArticleCategory[] */
/* @var $form yii\bootstrap\ActiveForm */
?>

<div class="article-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'title')->textInput(['maxlength' => true])?>

    <?= $form->field($model, 'slug')
        ->hint(Yii::t('backend', 'If you\'ll leave this field empty, slug will be generated automatically'))
        ->textInput([
        'maxlength' => true
    ])?>

    <?= $form->field($model, 'category_id')->dropDownList(\yii\helpers\ArrayHelper::map($categories, 'id', 'title'), [
        'prompt' => ''
    ])?>

    <?= $form->field($model, 'body')->widget(\common\ueditor\UEditor::className())?>

    <?= $form->field($model, 'thumbnail')->widget(Upload::className(), [
        'url' => [
            '/storage/file-storage/upload'
        ],
        'maxFileSize' => 5000000
    ]) // 5 MiB
;
    ?>

    <?= $form->field($model, 'attachments')->widget(Upload::className(), [
        'url' => [
            '/storage/file-storage/upload'
        ],
        'sortable' => true,
        'maxFileSize' => 10000000, // 10 MiB
        'maxNumberOfFiles' => 10
    ]);
    ?>

    <?= $form->field($model, 'view')->textInput(['maxlength' => true])?>

    <?= $form->field($model, 'status')->checkbox()?>
    <div class="form-group">
        <?= DateTimePicker::widget([
            'name' => 'Article[published_at]',
            'value' => $model->published_at? Yii::$app->formatter->asDatetime($model->published_at) : Yii::$app->formatter->asDatetime(time()),
            'pluginOptions' => [
                'autoclose'=> true,
                'format' => Yii::$app->formatter->datetimeFormat
            ]
        ])?>
    </div>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend', 'Update'), [
            'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary'
        ])?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
